() {printf ("e \ n ");};};
Int main (){D * D = new D;A * A = (A *) D;B * B = (B *) D;C * c = (C *) D ;;
D-> show ();A-> show ();B-> show ();
A-> dispa ();B-> dispb ();D-> dispd ();
D * D1 = (D *);D1-> show ();D1-> dispd ();D * D2 = (D *) B;D2-> show ();D2-> dispd ();
Char x = D-> data;Return 0;}
Each class has two virtual functions: Show () and dispx (). Classes A, B, and C are basic classes, while D is multi-inheritance. Finally, e inherits D. So what is the memory image of Class E? To answer
* a = (A *) d;B * B = (B *) d;C * c = (C *) d ;;
D-> Show ();A-> Show ();B-> Show ();
A-> DispA ();B-> DispB ();D-> DispD ();
D * d1 = (D *);D1-> Show ();D1-> DispD ();D * d2 = (D *) B;D2-> Show ();D2-> DispD ();
Char x = d-> data;Return 0;}
Each class has two virtual functions: Show () and DispX (). Classes A, B, and C are basic classes, while D is multi-inheritance. Finally, E inherits D. So what is the memory image of Class E? To answer this question, let's review the memory image of the bas
can only see three functions. You have to do it yourself.
Following the content in the previous article, we use the pf function pointer:
(* PF )();PF pf = NULL;
Write down the code in the main function:
* vtab = (*)*(*) (; *vtab != NULL; vtab++= (PF)** member = (*)
The output result of member variables is consistent with the conclusion in the previous art
what it wants internally. I only need to call the Seven functions I need when needed.
Old O: Oh ~~~, That's all... By the way, I have an emergency. I'm leaving. 88. Pay the bill ......
Small B: Hello! Hello... What are you doing when you are in such a hurry? Your wallet is lost :-)
Old O lost his wallet and rushed back to the office excitedly. He began to think ......
1. My program C should be able to call program B written by anyone. Then B must provide the functions F1 (), F2 (), F3 (
cannot care about what it wants internally. I only need to call the Seven functions I need when needed. old O: Oh ~~~, That's all... By the way, I have an emergency. I'm leaving. 88. Pay the bill... B: Hello! Hello ...... what do you do in such a hurry? The wallet is lost:-) although the old O lost his wallet, he rushed back to the office with excitement. He began to think ......
1. My program C should be able to call program B written by anyone. Then B must provide the functions F1 (), F2
internally. I only need to call the Seven functions I need when needed.Old O: Oh ~~~, That's all... By the way, I have an emergency. I'm leaving. 88. Pay the bill ......Small B: Hello! Hello... What are you doing when you are in such a hurry? Your wallet is lost :-)Old O lost his wallet and rushed back to the office excitedly. He began to think ......
1. My program C should be able to call program B written by anyone. Then B must provide the functions F1 (), F2 (), F3 (), K1 (), and K2 () as re
. He began to think ......1. My program C should be able to call program B written by anyone. Then B must provide the functions F1 (), F2 (), F3 (), K1 (), and K2 () as required in advance ().2. Basic is interpreted and executed, so its functions do not need to consider the writing order, as long as the function name is given, the interpreter can find it. But I am using C ++ ......3. After C ++ compilation, the Code does not contain the function name and only the function address. Therefore, I m
... What are you doing when you are in such a hurry? Your wallet is lost :-)Old O lost his wallet and rushed back to the office excitedly. He began to think ......
1. My program C should be able to call program B written by anyone. Then B must provide the functions F1 (), F2 (), F3 (), K1 (), and K2 () as required in advance ().2. Basic is interpreted and executed, so its functions do not need to consider the writing order, as long as the function name is given, the interpreter can find it. But
written by VC? But can c-style DLL be used universally? This is part of the guilt.
Back to the topic, because the base class does not have member data, the vtab is in the front or back, and the result is the same (just one person is in the queue, do you say it is in the front or the end ?). But let's talk about it. Now, the common compiler, vtab, is placed in front of the actual Member Data. Note that I ha
|+ -------------- +| ...... |
We can see that if we can override pvtable and construct a vftable table of our own, dynamic Association makesWe can change the program process!
Here is an overflow test:First write a program to see# Include Class classex{};Int buff [1];Classex obj1, obj2, * pobj;
Int main (void){Cout Return 0;}
The result of compiling and running with Cl is:0x00408998: 0x00408990: 0x00408991: 0x00408994The compiler puts the buff address behind it!Modify the program and chan
machine. For example, the ASCII character set in the character ' 0 ' represents the value is 48.In addition, a only byte-sized bit pattern can be represented by octal or hexadecimal, some special characters, such as the tab character, which are not directly represented (unlike a B c D e ....) ), which has a value of 11 in ASCII code. Therefore, it can be expressed as:#define VTAB ' 013 ' This is the representation of the octal system#define
, today = TUE, tomorrow = WED;/* Define three variables with a basic data type and assign an initial value. All of them are global variables */int x = ten, y =, z = 30;void Main (){printf ("%d%d%d/n", X, Y, z); Output: 10 20 30printf ("%d%d%d/n", Yesterday, today, tomorrow); Output: 1 2 3}3.2 When assigning an integer value to an enumerated variable, a type conversion is required.#include Enum Day {mon=1, TUE, WED, THU, FRI, SAT, SUN};void Main (){Enum Day yesterday, today, tomorrow;Yesterday =
efficiency of the program using the idispatch interface is relatively low. From the perspective of efficiency, ATL implements an interface mode called dual. Let's take a look at what a dual interface is:
Figure 1 dual INTERFACE STRUCTURE
It can be seen that the so-called double interface actually contains three interfaces in a virtual function table of a vtab (because any interface is derived from iunknown, so I will not emphasize iunknown, is called
the next page\ N line feed (LF), move the current position to the beginning of the next line\ R press enter (CR) to move the current position to the beginning of the line\ T horizontal tabulation (HT) (jump to the next tab)\ V vertical tabulation (VT)\ Represents a backslash character ''\'\ 'Represents a single quotation mark (Marker) character\ "Represents a double quotation mark character\ 0 null character (null)\ DDD 1-3 random characters\ Xhh any character in hexadecimal notation between 1
number. (Note 3)
From the implementation of the invoke () function, we can see that the execution efficiency of the program using the idispatch interface is relatively low. From the perspective of efficiency, ATL implements an interface mode called dual. Let's take a look at what a dual interface is:
Figure 1 dual INTERFACE STRUCTURE
It can be seen that the so-called double interface actually contains three interfaces in a virtual function table of a
the IDispatch interface program, its execution efficiency is relatively low. ATL has implemented an interface pattern called "dual Interface (dual)", which is based on efficiency. Let's take a look at what the two interfaces are: Figure one, dual interface (dual) structureAs can be seen, the so-called dual interface, in fact, in a vtab virtual function table accommodates three interfaces (because any interface is derived from IUnknown , so it does n
the invoke () function, we can see that the execution efficiency of the program using the idispatch interface is relatively low. From the perspective of efficiency, ATL implements an interface mode called dual. Let's take a look at what a dual interface is:
Figure 1 dual INTERFACE STRUCTURE
It can be seen that the so-called double interface actually contains three interfaces in a virtual function table of a vtab (because any interface is derived from
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.